<?

/***************************************************************************
 Jupiter Content System @ Jupiterportal.com
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

switch($a)
{
	//-----------------------------------------------------------------
	//  Live guests case
	//-----------------------------------------------------------------

	case 1:

		//-----------------------------------------------------------------
		//  Load online table
		//-----------------------------------------------------------------

		$guests = $db->getTable("SELECT ip, browser, refer, lang FROM online WHERE type = 'live' AND status = 'guest'");

		//-----------------------------------------------------------------
		//  Make a foreach to separate the results
		//-----------------------------------------------------------------

		if($guests != FALSE)
		{
			foreach($guests as $idx=>$guest)
			{
				//-----------------------------------------------------------------
				//  Make Layout
				//-----------------------------------------------------------------

				$layout .= "
					<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' onclick=window.open('http://www.dnsstuff.com/tools/whois.ch?ip={$guest['ip']}')>
					<td><a href='' title='{$language['Guests online desc']}'>{$guest['ip']}</a></td>
					<td>{$guest['browser']}</td>
					<td><a href='{$guest['refer']}'>".cuttext($guest['refer'],46)."</td>
					<td>{$guest['lang']}</td>
					</tr>";
			}
		}

		//-----------------------------------------------------------------
		//  If no guests online show info
		//-----------------------------------------------------------------

		else $layout .= "<tr><td class='con1' colspan='4'>{$language['Guests online desc2']}</td></tr>";

		//-----------------------------------------------------------------
		//  Start Layout
		//-----------------------------------------------------------------

		?>
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class='head'><td colspan='4'><?= $language['Guests online titles'] ?></td></tr>
			<tr class="bottom">
			<td width="20%"><?= $language['Guests online title'] ?></td>
			<td width="20%"><?= $language['Guests online title2'] ?></td>
			<td width="52%"><?= $language['Guests online title3'] ?></td>
			<td width="8%"><?= $language['Guests online title4'] ?></td>
			</tr>
			<?= $layout ?>
			</table>
		<?

	break;

	//-----------------------------------------------------------------
	//  Live members case
	//-----------------------------------------------------------------

	case 2:

		//-----------------------------------------------------------------
		//  Load users and online tables
		//-----------------------------------------------------------------

		$members = $db->getTable("SELECT user_id, user_authorization, user, user_email, user_flag, user_location, user_hideemail FROM online WHERE type = 'live' AND status = 'member'");

		//-----------------------------------------------------------------
		//  Make a foreach to separate the results
		//-----------------------------------------------------------------

		if($members != FALSE)
		{
			foreach($members as $idx=>$member)
			{
				//-----------------------------------------------------------------
				//  Hide email if option says so
				//-----------------------------------------------------------------

				if($member['user_hideemail'] == 1 && !isset($is_administrator) && !isset($is_webmaster)) $email = "<span class='inv'>Hidden</span>";
				elseif($member['user_hideemail'] == 1) $email = "<a href='mailto:{$member['user_email']}'>{$member['user_email']}</a> <span class='inv'>(Hidden)</span>";
				else $email = "<a href='mailto:{$member['user_email']}'>{$member['user_email']}</a>";

				//-----------------------------------------------------------------
				//  Make Layout
				//-----------------------------------------------------------------

				$layout .= "
					<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' onclick=window.location.href='$PHP_SELF?n=modules/users&a=1&d={$member['user_id']}'>
					<td align='center'>".find_flag($member['user_flag'],$member['user_location'])."</td>
					<td><a href='$PHP_SELF?n=modules/users&a=1&d={$member['user_id']}'>{$member['user']}</td>
					<td>$email</td>
					<td>".find_authorization($member['user_authorization'])."</td>
					</tr>";
			}
		}

		//-----------------------------------------------------------------
		//  If no members online show info
		//-----------------------------------------------------------------

		else $layout .= "<tr><td class='con1' colspan='4'>{$language['Members online desc']}</td></tr>";

		//-----------------------------------------------------------------
		//  Start Layout
		//-----------------------------------------------------------------

		?>
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class='head'><td colspan='4'><?= $language['Guests online titles2'] ?></td></tr>
			<tr class="bottom">
			<td width="1%"><?= $language['Members online title'] ?></td>
			<td width="40%"><?= $language['Members online title2'] ?></td>
			<td width="45%"><?= $language['Members online title3'] ?></td>
			<td width="14%"><?= $language['Members online title4'] ?></td>
			</tr>
			<?= $layout ?>
			</table>
		<?

	break;

	//-----------------------------------------------------------------
	//  Loged guests case
	//-----------------------------------------------------------------

	case 3:

		//-----------------------------------------------------------------
		//  Filter Acces Rightes
		//-----------------------------------------------------------------

		if(isset($is_guest) || isset($is_user))
		header("location: $PHP_SELF?n=modules/online&a=1");

		//-----------------------------------------------------------------
		//  Navigation Stuff
		//-----------------------------------------------------------------

		$rows_per_page = $config['nav_log'];
		$numrows = $db->getInfo_countRows("online","type = 'log' AND status = 'guest'");

		$lastpage = ceil($numrows/$rows_per_page);
		$p = (int)$p;

		if ($p < 1) $p = 1;
		elseif ($p > $lastpage) $p = $lastpage;

		if($numrows != FALSE) $limit = 'LIMIT ' .($p - 1) * $rows_per_page .',' .$rows_per_page;
		else $limit = NULL;

		//-----------------------------------------------------------------
		//  Sorting Stuff
		//-----------------------------------------------------------------

		if(!isset($s)) $s = 'date'; // Default value
		if(!isset($t)) $t = 'DESC'; // Default value

		$sname1 = "date";
		$sname2 = "ip";
		$sname3 = "browser";
		$sname4 = "refer";
		$sname5 = "lang";

		if($t == "ASC"){ $t = "DESC"; $t2 = "ASC"; }
		else{ $t = "ASC"; $t2 = "DESC"; }

		if($t == "ASC"){ $t3 = "<img src='templates/$template/images/misc/up.gif' border='0'>";}
		else{ $t3 = "<img src='templates/$template/images/misc/down.gif' border='0'>";}

		if($s == 1) $s = $sname1;
		if($s == 2) $s = $sname2;
		if($s == 3) $s = $sname3;
		if($s == 4) $s = $sname4;
		if($s == 5) $s = $sname5;

		//-----------------------------------------------------------------
		//  Load log table
		//-----------------------------------------------------------------

		$guests = $db->getTable("SELECT date, ip, browser, lang, refer FROM online WHERE type = 'log' AND status = 'guest' ORDER BY ".$db->escape($s)." ".$db->escape($t2)." ".$db->escape($limit)."");

		//-----------------------------------------------------------------
		//  Make a foreach to separate the results
		//-----------------------------------------------------------------

		if($guests != FALSE)
		{
			foreach($guests as $idx=>$guest)
			{
				//-----------------------------------------------------------------
				//  Make Layout
				//-----------------------------------------------------------------

				$layout .= "
					<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' onclick=window.open('http://www.dnsstuff.com/tools/whois.ch?ip={$guest['ip']}')>
					<td><img src='templates/$template/images/status/stat".arrow_legend($guest['date']).".gif' border='0' alt='".arrow_legend($guest['date'])."'></td>
					<td><a href='' title='{$language['Guests online desc']}'>{$guest['ip']}</a></td>
					<td>{$guest['browser']}</td>
					<td><a href='{$guest['refer']}'>".cuttext($guest['refer'],45)."</a></td>
					<td>{$guest['lang']}</td>
					</tr>";

				//-----------------------------------------------------------------
				//  Start from 1
				//-----------------------------------------------------------------

				$idx ++;
			}
		}
		else
		{
			//-----------------------------------------------------------------
			//  Reset to 0
			//-----------------------------------------------------------------

			$idx = 0;

			//-----------------------------------------------------------------
			//  Make Layout
			//-----------------------------------------------------------------

			$layout .= "<tr class='con1'><td colspan='5'>{$language['Guests online desc3']}</td></tr>";
		}

		//-----------------------------------------------------------------
		//  Navigation Code
		//-----------------------------------------------------------------

		if ($p == 1) $nav_prev = "<tr><td class='con1' align='right'>&nbsp;</td>";
		else
		{
			$prevpage = $p-1;
			$nav_prev = "<tr><td class='con1' align='left'><a href='$PHP_SELF?n=modules/online&a=3&s=$s&t=$t2&p=$prevpage'>&laquo; {$language['Online previous']}</a></td>";
		}

		$nav_nr = '[ '.paginate($lastpage, $p, $PHP_SELF.'?n=modules/online&a=3&s='.$s.'&t='.$t2).' ]';

		if($idx == $numrows) $nav_nr = NULL;

		if ($p == $lastpage)
			$nav_next = "<td class='con1' align='right'>&nbsp;</td></tr>";
		else
		{
			$nextcode = $numrows - $idx * $p;
			if($nextcode > $idx) $how_next = $idx;
			else $how_next = $nextcode;

			$nextpage = $p+1;

			$nav_next = "<td class='con1' align='right'><a href='$PHP_SELF?n=modules/online&a=3&s=$s&t=$t2&p=$nextpage'>{$language['Online next']} $how_next &raquo;</a></td></tr>";
		}

		if($idx == $numrows)
		{
			$nav_head = "class='con1'";
			$nav = NULL;
		}
		else
		{
			$nav_head = "class='head'";
			$nav = ''.$nav_prev.''.$nav_next.'';
		}

		//-----------------------------------------------------------------
		//  Start Layout + Navigation
		//-----------------------------------------------------------------

		?>
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class='con1'><td><a href='<?= $PHP_SELF ?>?n=modules/admin'><?= $language['Admin name'] ?></a> &raquo; <?= $language['Guests online titles3'] ?></td></tr>
			</table>
			<table><tr><td></td></tr></table>		
		
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class='head'><td colspan='5'><?= $language['Guests online titles3'] ?></td></tr>
			<tr class="bottom">
			<td width="1%" align="center"><a href="<?= $PHP_SELF ?>?n=modules/online&a=3&s=1&t=<?= $t ?>&p=<?= $p ?>"><? if($s == $sname1) echo $t3; else echo "*" ?></a></td>
			<td width="20%"><a href="<?= $PHP_SELF ?>?n=modules/online&a=3&s=2&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Guests online title'] ?> <? if($s == $sname2) echo $t3 ?></a></td>
			<td width="20%"><a href="<?= $PHP_SELF ?>?n=modules/online&a=3&s=3&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Guests online title2'] ?> <? if($s == $sname3) echo $t3 ?></a></td>
			<td width="50%"><a href="<?= $PHP_SELF ?>?n=modules/online&a=3&s=4&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Guests online title3'] ?> <? if($s == $sname4) echo $t3 ?></a></td>
			<td width="9%"><a href="<?= $PHP_SELF ?>?n=modules/online&a=3&s=5&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Guests online title4'] ?> <? if($s == $sname5) echo $t3 ?></a></td>
			</tr>
			<?= $layout ?>
			</table><table><tr><td></td></tr></table>
			
			<table class="main" cellspacing="1" cellpadding="4">
			<col width="50%"><col width="50%">
			<tr><td class="con1"><img src="templates/<?= $template ?>/images/status/stat1.gif" border="0"> <?= $language['Indicator1'] ?></td><td class="con1"><img src="templates/<?= $template ?>/images/status/stat3.gif" border="0"> <?= $language['Indicator3'] ?></td></tr>
			<tr><td class="con1"><img src="templates/<?= $template ?>/images/status/stat2.gif" border="0"> <?= $language['Indicator2'] ?></td><td class="con1"><img src="templates/<?= $template ?>/images/status/stat4.gif" border="0"> <?= $language['Indicator4'] ?></td></tr>
			</table>
			<table><tr><td></td></tr></table>
			
			<table class="main" cellspacing="1" cellpadding="4" width="100%">
			<col width="50%"><col width="50%">
			<tr <?= $nav_head ?>>
			<td colspan="2">
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<col width="50%"><col width="50%">
			<tr class="empty">
			<td align="left"><?= $language['Online nav'] ?> <b><?= $idx ?></b> <?= $language['Online nav2'] ?> <b><?= $numrows ?></b></td>
			<td align="right"><?= $nav_nr ?></td>
			</tr>
			</table>
			</td>
			</tr>
			<?= $nav ?>
			</table>
		<?

	break;

	//-----------------------------------------------------------------
	//  Loged members case
	//-----------------------------------------------------------------

	case 4:

		//-----------------------------------------------------------------
		//  Filter Acces Rightes
		//-----------------------------------------------------------------

		if(isset($is_guest) || isset($is_user))
			header("location: $PHP_SELF?n=modules/online&a=1");

		//-----------------------------------------------------------------
		//  Navigation Stuff
		//-----------------------------------------------------------------

		$rows_per_page = $config['nav_log'];
		$numrows = $db->getInfo_countRows("online","type = 'log' AND status = 'member'");

		$lastpage = ceil($numrows/$rows_per_page);
		$p = (int)$p;

		if ($p < 1) $p = 1;
		elseif ($p > $lastpage) $p = $lastpage;

		if($numrows != FALSE) $limit = 'LIMIT ' .($p - 1) * $rows_per_page .',' .$rows_per_page;
		else $limit = NULL;

		//-----------------------------------------------------------------
		//  Sorting Stuff
		//-----------------------------------------------------------------

		if(!isset($s)) $s = 'date'; // Default value
		if(!isset($t)) $t = 'DESC'; // Default value

		$sname1 = "date";
		$sname2 = "user_flag";
		$sname3 = "user";
		$sname4 = "user_email";
		$sname5 = "user_authorization";

		if($t == "ASC"){ $t = "DESC"; $t2 = "ASC"; }
		else{ $t = "ASC"; $t2 = "DESC"; }

		if($t == "ASC"){ $t3 = "<img src='templates/$template/images/misc/up.gif' border='0'>";}
		else{ $t3 = "<img src='templates/$template/images/misc/down.gif' border='0'>";}

		if($s == 1) $s = $sname1;
		if($s == 2) $s = $sname2;
		if($s == 3) $s = $sname3;
		if($s == 4) $s = $sname4;
		if($s == 5) $s = $sname5;

		//-----------------------------------------------------------------
		//  Load users and log tables
		//-----------------------------------------------------------------

		$members = $db->getTable("SELECT o.user_id, o.user, o.user_email, o.user_hideemail, o.user_flag, o.user_location, o.user_authorization, o.date, u.id FROM online AS o LEFT JOIN users AS u ON o.user_id=u.id WHERE o.type = 'log' AND o.status = 'member' ORDER BY ".$db->escape($s)." ".$db->escape($t2)." ".$db->escape($limit)."");

		//-----------------------------------------------------------------
		//  Make a foreach to separate the results
		//-----------------------------------------------------------------

		if($members != FALSE)
		{
			foreach($members as $idx=>$member)
			{
				//-----------------------------------------------------------------
				//  See if user exists
				//-----------------------------------------------------------------

				if(isset($member['id']))
				{
					$profile_link = "onclick=window.location.href='$PHP_SELF?n=modules/users&a=1&d={$member['user_id']}'";
					$user_link = "<a href='$PHP_SELF?n=modules/users&a=1&d={$member['user_id']}'>{$member['user']}</a>";
				}
				else
				{
					$profile_link = NULL;
					$user_link = $member['user'];
				}

				//-----------------------------------------------------------------
				//  Hide email if option says so
				//-----------------------------------------------------------------

				if($member['user_hideemail'] == 1 && !isset($is_administrator) && !isset($is_webmaster)) $email = "<span class='inv'>Hidden</span>";
				elseif($member['user_hideemail'] == 1) $email = "<a href='mailto:{$member['user_email']}'>{$member['user_email']}</a> <span class='inv'>(Hidden)</span>";
				else $email = "<a href='mailto:{$member['user_email']}'>{$member['user_email']}</a>";

				//-----------------------------------------------------------------
				//  Make Layout
				//-----------------------------------------------------------------

				$layout .= "
					<tr class='".row2color($idx)."' onMouseOver=this.className='con3' onMouseOut=this.className='".row2color($idx)."' $profile_link>
					<td><img src='templates/$template/images/status/stat".arrow_legend($member['date']).".gif' border='0' alt='".arrow_legend($member['date'])."'></td>
					<td align='center'>".find_flag($member['user_flag'],$member['user_location'])."</td>
					<td>$user_link</td>
					<td>$email</td>
					<td>".find_authorization($member['user_authorization'])."</td>
					</tr>";

				//-----------------------------------------------------------------
				//  Start from 1
				//-----------------------------------------------------------------

				$idx ++;
			}
		}
		else
		{
			//-----------------------------------------------------------------
			//  Reset to 0
			//-----------------------------------------------------------------

			$idx = 0;

			//-----------------------------------------------------------------
			//  Make Layout
			//-----------------------------------------------------------------

			$layout .= "<tr class='con1'><td colspan='5'>{$language['Members online desc2']}</td></tr>";
		}

		//-----------------------------------------------------------------
		//  Navigation Code
		//-----------------------------------------------------------------

		if ($p == 1) $nav_prev = "<tr><td class='con1' align='right'>&nbsp;</td>";
		else
		{
			$prevpage = $p-1;
			$nav_prev = "<tr><td class='con1' align='left'><a href='$PHP_SELF?n=modules/online&a=4&s=$s&t=$t2&p=$prevpage'>&laquo; {$language['Online previous']}</a></td>";
		}

		$nav_nr = '[ '.paginate($lastpage, $p, $PHP_SELF.'?n=modules/online&a=4&s='.$s.'&t='.$t2).' ]';

		if($idx == $numrows) $nav_nr = NULL;

		if ($p == $lastpage)
			$nav_next = "<td class='con1' align='right'>&nbsp;</td></tr>";
		else
		{
			$nextcode = $numrows - $idx * $p;
			if($nextcode > $idx) $how_next = $idx;
			else $how_next = $nextcode;

			$nextpage = $p+1;

			$nav_next = "<td class='con1' align='right'><a href='$PHP_SELF?n=modules/online&a=4&s=$s&t=$t2&p=$nextpage'>{$language['Online next']} $how_next &raquo;</a></td></tr>";
		}

		if($idx == $numrows)
		{
			$nav_head = "class='con1'";
			$nav = NULL;
		}
		else
		{
			$nav_head = "class='head'";
			$nav = ''.$nav_prev.''.$nav_next.'';
		}

		//-----------------------------------------------------------------
		//  Start Layout + Navigation
		//-----------------------------------------------------------------

		?>
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class='con1'><td><a href='<?= $PHP_SELF ?>?n=modules/admin'><?= $language['Admin name'] ?></a> &raquo; <?= $language['Guests online titles4'] ?></td></tr>
			</table>
			<table><tr><td></td></tr></table>			
		
			<table class="main" cellspacing="1" cellpadding="4">
			<tr class='head'><td colspan='5'><?= $language['Guests online titles4'] ?></td></tr>
			<tr class="bottom">
			<td width="1%" align="center"><a href="<?= $PHP_SELF ?>?n=modules/online&a=4&s=1&t=<?= $t ?>&p=<?= $p ?>"><? if($s == $sname1) echo $t3; else echo "*" ?></a></td>
			<td width="6%" align="center"><a href="<?= $PHP_SELF ?>?n=modules/online&a=4&s=2&t=<?= $t ?>&p=<?= $p ?>"><? if($s == $sname2) echo $t3; else echo $language['Members online title'] ?></a></td>
			<td width="36%"><a href="<?= $PHP_SELF ?>?n=modules/online&a=4&s=3&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Members online title2'] ?> <? if($s == $sname3) echo $t3 ?></a></td>
			<td width="35%"><a href="<?= $PHP_SELF ?>?n=modules/online&a=4&s=4&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Members online title3'] ?> <? if($s == $sname4) echo $t3 ?></a></td>
			<td width="22%"><a href="<?= $PHP_SELF ?>?n=modules/online&a=4&s=5&t=<?= $t ?>&p=<?= $p ?>"><?= $language['Members online title4'] ?> <? if($s == $sname5) echo $t3 ?></a></td>
			</tr>
			<?= $layout ?>
			</table><table><tr><td></td></tr></table>
			
			<table class="main" cellspacing="1" cellpadding="4">
			<col width="50%"><col width="50%">
			<tr><td class="con1"><img src="templates/<?= $template ?>/images/status/stat1.gif" border="0"> <?= $language['Indicator1'] ?></td><td class="con1"><img src="templates/<?= $template ?>/images/status/stat3.gif" border="0"> <?= $language['Indicator3'] ?></td></tr>
			<tr><td class="con1"><img src="templates/<?= $template ?>/images/status/stat2.gif" border="0"> <?= $language['Indicator2'] ?></td><td class="con1"><img src="templates/<?= $template ?>/images/status/stat4.gif" border="0"> <?= $language['Indicator4'] ?></td></tr>
			</table>
			<table><tr><td></td></tr></table>
			
			<table class="main" cellspacing="1" cellpadding="4" width="100%">
			<col width="50%"><col width="50%">
			<tr <?= $nav_head ?>>
			<td colspan="2">
			<table border="0" cellspacing="0" cellpadding="0" width="100%">
			<col width="50%"><col width="50%">
			<tr class="empty">
			<td align="left"><?= $language['Online nav'] ?> <b><?= $idx ?></b> <?= $language['Online nav2'] ?> <b><?= $numrows ?></b></td>
			<td align="right"><?= $nav_nr ?></td>
			</tr>
			</table>
			</td>
			</tr>
			<?= $nav ?>
			</table>
		<?

	break;

	//-----------------------------------------------------------------
	//  Default case
	//-----------------------------------------------------------------

	default: header("location: $PHP_SELF?n=modules/online&a=1");
}

?>